/**********************************************
** @Author: phy
** @Date:   2017-12-12 14:17:37
** @Last Modified by:   phy
***********************************************/
package models

import (
	"strconv"
	"github.com/astaxie/beego"
	//"time"
	"fmt"
	//"fmt"
	"github.com/astaxie/beego/orm"
	//"errors"
)
//记录
type GMAddRecord struct {
	Id int64
	Manager_id int
	Manager_name string
	User_id int64
	Nickname string
	Gold_type int
	Amount int64
	Operation_time string
	Explain string
	Unix_time int64
}



func (a *GMAddRecord) TableName() string {
	return TableName("GMAddRecord")
}

func  GMAddRecordGetListSQL(sql string) ([]*GMAddRecord, int64){
	sql = "SELECT * FROM GMAddRecord"

	list2 := make([]*GMAddRecord, 0);
	var list []GMAddRecord
	var o = orm.NewOrm();
	o.Using("default")
	//query := o.QueryTable(TableName("GMAddRecord"))
	num,_ :=o.Raw(sql).QueryRows(&list);
	fmt.Println("#########################123")
	fmt.Println(list);
	return list2 ,num;
}

func  GMAddRecordGetList(page, pageSize int,date1,date2 string, filters ...interface{}) ([]*GMAddRecord, int64) {
	offset := (page - 1) * pageSize
	list := make([]*GMAddRecord, 0)
	var o = orm.NewOrm();
	o.Using("default")
	query := o.QueryTable(TableName("GMAddRecord"))
	if len(filters) > 0 {
		l := len(filters)
		for k := 0; k < l; k += 2 {
			query = query.Filter(filters[k].(string), filters[k+1])
		}
	}

	t2 := beego.StringTimeToUnix(date2,"2006-01-02")
	t2 = t2 + 24* 3600 -1;
	date2 = beego.UnixTimeToString(t2,"");

	t1:= beego.StringTimeToUnix(date1,"2006-01-02");
	date1 = beego.UnixTimeToString(t1,"");

	fmt.Println("***************************",date1,date2)
	if date1 !="" && date2 != "" {
		//query = query.Filter("operation_time__in",date1,date2);
		query = query.Filter("operation_time__gte",date1);
		query = query.Filter("operation_time__lte",date2);
	}
	

	total, _ := query.Count()
	query.OrderBy("-Unix_time").Limit(pageSize, offset).All(&list)


	return list, total
}
func (data *GMAddRecord) GMAddRecordInSertValues() error {
	o:= orm.NewOrm();

	query :=o.QueryTable(TableName("GMAddRecord"))
	i, _ := query.PrepareInsert()

	_,err := i.Insert(data);

	
	defer i.Close() // 别忘记关闭 statement

	return err
}
//==============================================================================================================
//赠送礼物 相关操作


//giveGift
type UserGiveGift struct {
	ID int64
	GiveGiftID int64
	GiftName string
	GiveUserID int64
	GiveGameID int64
	GiveNickName string

	ReceiveUserID int64
	ReceiveGameID int64
	ReceiveNickName string

	GiftSinglePrice int64
	GiftNum	int64
	GiftPrice int64
	Gold int64
	GiveTime int64
	Status int
	ReceiveTime int64
	GiveZeroTime int64
	Gid int 
	BackTime string

}



func (a *UserGiveGift) TableName() string {
	return TableName("UserGiveGift")
}

func  GiveGiftRecordGetList(page, pageSize int,date1,date2 int64,giveUserOrGetUser int, filters ...interface{}) ([]*UserGiveGift, int64) {
	offset := (page - 1) * pageSize
	list := make([]*UserGiveGift, 0)
	var o = orm.NewOrm();
	o.Using("goldlog")
	query := o.QueryTable(TableName("UserGiveGift"))
	if len(filters) > 0 {
		l := len(filters)
		for k := 0; k < l; k += 2 {
			query = query.Filter(filters[k].(string), filters[k+1])
		}
	}

	//0 没选择 默认为赠送时间范围 1 赠送者时间 2 领取者时间
	if date1 !=0 && date2 != 0  {
		if giveUserOrGetUser == 1 || giveUserOrGetUser == 0{
			query = query.Filter("GiveTime__gte",date1);
			query = query.Filter("GiveTime__lte",date2);
		}else if giveUserOrGetUser == 2{
			query = query.Filter("ReceiveTime__gte",date1);
			query = query.Filter("ReceiveTime__lte",date2);
	
		}
	}

	total, _ := query.Count()
	//fmt.Println("DDDDDDDDDDDDDDDDDDDD",pageSize,offset);
	query.OrderBy("ID").Limit(pageSize, offset).All(&list)


	return list, total
}

/*==============================================================================================================
//游戏公告 相关操作
CREATE TABLE `NoticeList` (
  `rid` int(11) NOT NULL AUTO_INCREMENT,
  `Content` varchar(256) DEFAULT NULL COMMENT '公告内容',
  `SEPTIME` bigint(20) NOT NULL DEFAULT '0' COMMENT '间隔时间 单位秒',
  `TIMES` bigint(20) DEFAULT '0' COMMENT '重复次数',
  `STATUS` int(10) NOT NULL DEFAULT '0' COMMENT '0-未发送 1-已发送',
  `AddTime` datetime DEFAULT NULL,
  PRIMARY KEY (`rid`)
) ENGINE=InnoDB AUTO_INCREMENT=43 DEFAULT CHARSET=utf8;
 ==============================================================================================================*/
type NoticeList struct {
	Rid int `orm:"pk"` 
	Content string
	SEPTIME int64
	TIMES int64
	STATUS int
	AddTime string
}


func (a *NoticeList) TableName() string {
	return TableName("NoticeList")
}

func  NoticeListGetList(page, pageSize int, filters ...interface{}) ([]*NoticeList, int64) {
	offset := (page - 1) * pageSize
	list := make([]*NoticeList, 0)
	var o = orm.NewOrm();
	o.Using("goldlog")
	query := o.QueryTable(TableName("NoticeList"))
	if len(filters) > 0 {
		l := len(filters)
		for k := 0; k < l; k += 2 {
			query = query.Filter(filters[k].(string), filters[k+1])
		}
	}

	total, _ := query.Count()
	query.OrderBy("Rid").Limit(pageSize, offset).All(&list)


	return list, total
}

func  NoticeListDelete(page, pageSize int, filters ...interface{}) (int64,error) {

	var o = orm.NewOrm();
	o.Using("goldlog")
	query := o.QueryTable(TableName("NoticeList"))

	if len(filters) > 0 {
		l := len(filters)
		for k := 0; k < l; k += 2 {
			query = query.Filter(filters[k].(string), filters[k+1])
		}
	}
	query = query.Filter("rid",128);
	num, err := query.Delete();
	return num,err;
}

//插入值
func NoticeListGetInsertValue()(*NoticeList){
	var nl = new(NoticeList);
	nl.AddTime = beego.GetTimeNowString();
	nl.Content = "";
	nl.SEPTIME = 0;
	nl.TIMES = 0;
	nl.STATUS = 0;

	return nl;
}

func NoticeListInsertValue(ras *NoticeList) ( int64, error) {
	fmt.Println(ras);
	o:= orm.NewOrm();

	query :=o.QueryTable(TableName("NoticeList"))
	i, _ := query.PrepareInsert()

	n,err := i.Insert(ras);

	
	defer i.Close() // 别忘记关闭 statement
	fmt.Println("===========NoticeListInsertValue插入数据结果========",n,err)

	return n, err
}
/*==============================================================================================================
//游戏公告 相关操作
CREATE TABLE `NoticeCtroInfo` (
  `ID` int(10) NOT NULL AUTO_INCREMENT,
  `CONTENT` varchar(256) NOT NULL DEFAULT '' COMMENT '公告内容',
  `SEPTIME` bigint(20) NOT NULL DEFAULT '0' COMMENT '间隔时间 单位秒',
  `TIMES` bigint(20) NOT NULL DEFAULT '0' COMMENT '重复次数',
  `STATUS` int(10) NOT NULL DEFAULT '0' COMMENT '0-未发送 1-已发送',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

 ==============================================================================================================*/
 type NoticeCtroInfo struct {
	ID int `orm:"pk"` 
	CONTENT string
	SEPTIME int64
	TIMES int64
	STATUS int
}


func (a *NoticeCtroInfo) TableName() string {
	return TableName("NoticeCtroInfo")
}

func  NoticeCtroInfoGetList(page, pageSize int, filters ...interface{}) ([]*NoticeCtroInfo, int64) {
	offset := (page - 1) * pageSize
	list := make([]*NoticeCtroInfo, 0)
	var o = orm.NewOrm();
	o.Using("goldlog")
	query := o.QueryTable(TableName("NoticeCtroInfo"))
	if len(filters) > 0 {
		l := len(filters)
		for k := 0; k < l; k += 2 {
			query = query.Filter(filters[k].(string), filters[k+1])
			
		}
	}

	total, _ := query.Count()
	query.OrderBy("id").Limit(pageSize, offset).All(&list)


	return list, total
}

func NoticeCtroInfoDelete(page, pageSize int, filters ...interface{}) (int64,error) {

	var o = orm.NewOrm();
	o.Using("goldlog")
	query := o.QueryTable(TableName("NoticeCtroInfo"))

	if len(filters) > 0 {
		l := len(filters)
		for k := 0; k < l; k += 2 {
			query = query.Filter(filters[k].(string), filters[k+1])
		}
	}

	num, err := query.Delete();
	return num,err;
}

//插入值
func NoticeCtroInfoGetInsertValue()(*NoticeCtroInfo){
	var nl = new(NoticeCtroInfo);
	nl.CONTENT = "";
	nl.SEPTIME = 0;
	nl.TIMES = 0;
	nl.STATUS = 0;

	return nl;
}

func NoticeCtroInfoInsertValue(ras *NoticeCtroInfo) ( int64, error) {
	fmt.Println(ras);
	o:= orm.NewOrm();
	o.Using("goldlog")
	query :=o.QueryTable(TableName("NoticeCtroInfo"))
	i, _ := query.PrepareInsert()

	n,err := i.Insert(ras);

	
	defer i.Close() // 别忘记关闭 statement
	fmt.Println("===========NoticeCtroInfonsertValue插入数据结果========",n,err)

	return n, err
}


/*==============================================================================================================
//管理员日志
CREATE TABLE `GMOperationLog` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `manager_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '操作管理员ID',
  `manager_name` varchar(33) NOT NULL DEFAULT '' COMMENT '管理员账号',
  `operation_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '操作时间',
  `operation_IP` varchar(33) DEFAULT '' COMMENT '操作IP',
  `explain` varchar(1000) DEFAULT '' COMMENT '操作内容',
  `status` int(10) DEFAULT '0',
  `unix_time` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;



 ==============================================================================================================*/
 type GMOperationLog struct {
	Id int `orm:"pk"` 
	Manager_id int64
	Manager_account string
	Manager_name string
	Operation_time string
	Operation_IP string
	Explain string
	Status int 
	Unix_time int64
	ControllerName string
	ActionName string
}

func (a *GMOperationLog) TableName() string {
	return TableName("GMOperationLog")
}

func GMOperationLogGetList(page, pageSize int,date1,date2 string, filters ...interface{}) ([]*GMOperationLog, int64) {
	offset := (page - 1) * pageSize
	list := make([]*GMOperationLog, 0)
	var o = orm.NewOrm();
	o.Using("goldlog")
	query := o.QueryTable(TableName("GMOperationLog"))
	if len(filters) > 0 {
		l := len(filters)
		for k := 0; k < l; k += 2 {
			query = query.Filter(filters[k].(string), filters[k+1])
			
		}
	}

	
	t2 := beego.StringTimeToUnix(date2,"2006-01-02")
	t2 = t2 + 24* 3600 -1;
	date2 = beego.UnixTimeToString(t2,"");

	t1:= beego.StringTimeToUnix(date1,"2006-01-02");
	date1 = beego.UnixTimeToString(t1,"");

	fmt.Println("***************************",date1,date2)
	if date1 !="" && date2 != "" {
		//query = query.Filter("operation_time__in",date1,date2);
		query = query.Filter("operation_time__gte",date1);
		query = query.Filter("operation_time__lte",date2);
	}

	total, _ := query.Count()
	query.OrderBy("-id").Limit(pageSize, offset).All(&list)


	return list, total
}

//插入值

func GMOperationLogInsertValue(ras *GMOperationLog) ( int64, error) {
	//fmt.Println(ras);
	o:= orm.NewOrm();
	o.Using("goldlog")
	query :=o.QueryTable(TableName("GMOperationLog"))
	i, _ := query.PrepareInsert()

	n,err := i.Insert(ras);

	
	defer i.Close() // 别忘记关闭 statement
	fmt.Println("===========GMOperationLogInsertValue插入数据结果========",n,err)

	return n, err
}


/*==============================================================================================================
//管理员日志 IOS充值记录表

CREATE TABLE `UserPurchaseInfo` (
	`ID` int(10) unsigned NOT NULL AUTO_INCREMENT,
	`USERID` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '用户ID',
	`GAMEID` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '用户ID',
	`NICKNAME` tinyblob NOT NULL COMMENT '昵称',
	`RMB` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '用户ID',
	`PLATFORM` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '平台ID',
	`NPACKAGE` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '那个包充值的',
	`PURCHASETIME` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '充值时间',
	`DIAMOND` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '充值获得钻石',
	`ITEMID` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '道具ID',
	`ITEMCOUNT` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '道具数量',
	`SCORE` bigint(20) NOT NULL DEFAULT '0' COMMENT '金币',
	`LVSIGN` int(10) NOT NULL DEFAULT '0' COMMENT '商人等级',
	PRIMARY KEY (`ID`)
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 ==============================================================================================================*/

type  UserPurchaseInfo struct {
	ID  int `orm:"pk;auto"` //int(10) unsigned
	USERID int// int(10) unsi
	GAMEID int //` int(10) unsi
	NICKNAME string//` tinyblob N
	RMB int //` int(10) unsigne
	PLATFORM int //` int(10) un
	NPACKAGE int  //int` int(10) un
	PURCHASETIME int64//int` bigint
	DIAMOND int//` bigint(20) 
	ITEMID int //` int(10) unsi
	ITEMCOUNT int //` int(10) u
	SCORE int64//` bigint(20) NO
	LVSIGN int //` int(10) NOT 
}

func (a *UserPurchaseInfo) TableName() string {
	return TableName("UserPurchaseInfo")
}

func UserPurchaseInfoGetList(page, pageSize int,date1,date2 int64, filters ...interface{}) ([]*UserPurchaseInfo, int64) {
	offset := (page - 1) * pageSize
	list := make([]*UserPurchaseInfo, 0)
	var o = orm.NewOrm();
	o.Using("goldlog")
	query := o.QueryTable(TableName("UserPurchaseInfo"))
	if len(filters) > 0 {
		l := len(filters)
		for k := 0; k < l; k += 2 {
			query = query.Filter(filters[k].(string), filters[k+1])
			
		}
	}

	if date1 !=0 && date2 != 0 {
		//query = query.Filter("operation_time__in",date1,date2);
		query = query.Filter("PURCHASETIME__gte",date1);
		query = query.Filter("PURCHASETIME__lte",date2);
	}

	total, _ := query.Count()
	query.OrderBy("id").Limit(pageSize, offset).All(&list)

	fmt.Println(list);
	return list, total
}


/*==============================================================================================================
//在线统计

CREATE TABLE `UserOnlineInfo` (
  `ID` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `USERID` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '用户ID',
  `KINDID` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '游戏KIND',
  `PLATFORM` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '平台ID',
  `NTYPE` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '0-金币场 1-比赛场',
  `ROOMID` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '0-大厅 1-房间',
  `LASTLOGINTIME` bigint(20) NOT NULL DEFAULT '0' COMMENT '上次登录时间',
  `LVSIGN` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT '贵宾等级',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=34 DEFAULT CHARSET=utf8;
 ==============================================================================================================*/

type  UserOnlineInfo struct {
	ID  int `orm:"pk;auto"` //int(10) unsigned
	USERID  int//(10) unsigned NOT N
	KINDID int//(10) unsigned NOT N
	PLATFORM int//(10) unsigned NOT
	NTYPE int//(10) unsigned NOT NU
	ROOMID int//(10) unsigned NOT N
	LASTLOGINTIME int64//(20) NOT 
	LVSIGN int//smallint(5) unsigned N

}

func (a *UserOnlineInfo) TableName() string {
	return TableName("UserOnlineInfo")
}

type OnlineCountInfo struct{
	KINDID int
	ROOMID int
	NUM int
}

func UserOnlineInfoGetList(platform int,date1,date2 int64, filters ...interface{}) (*[]OnlineCountInfo, int64) {
	//offset := (page - 1) * pageSize
	//list := make([]*OnlineCountInfo, 0)
	var o = orm.NewOrm();
	o.Using("goldlog")
	var maps []OnlineCountInfo//[]orm.Params

	num,err := o.Raw("SELECT  KINDID,ROOMID , COUNT(*) as 'NUM' FROM UserOnlineInfo GROUP BY KINDID, ROOMID").QueryRows(&maps);
	if err != nil {
		beego.Error("UserOnlineInfoGetList查询出错：" + err.Error())
	}
	
	/* for i:=0;i<len(maps);i++ {
		//r := new(OnlineCountInfo)
		//r.KINDID = maps[i].KINDID

		fmt.Println(maps[i].NUM);
		fmt.Println("###############",len(maps))
	}  */

	
	return &maps, num;
}


/*==============================================================================================================
//在线统计 所有人在线

CREATE TABLE `AllUserOnlineCount` (
  `ID` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `USERCOUNT` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '在线人数',
  `WRITETIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


 ==============================================================================================================*/
 type  AllUserOnlineCount struct {
	ID  int `orm:"pk;auto"` //int(10) unsigned
	USERCOUNT int//
	//WRITETIME string `orm:"pk;auto"`//
}
 func (a *AllUserOnlineCount) TableName() string {
	return TableName("AllUserOnlineCount")
}

//每几分钟 从 AllUserOnlineCount 表中取总人数写入此表
func AllUserOnlineCountInsertValue()( int64, error){

	var o = orm.NewOrm();
	o.Using("goldlog")
	cnt, err := o.QueryTable("UserOnlineInfo").Count() // SELECT COUNT(*) FROM USER
	if err != nil {
		beego.Error(err.Error());
	}
	
	//fmt.Printf("当前在线人数写入Count Num: %d", cnt);

	var ras AllUserOnlineCount;
	ras.USERCOUNT = int(cnt);
	query := o.QueryTable(TableName("AllUserOnlineCount"))

	i, _ := query.PrepareInsert()
	
	n,err := i.Insert(&ras);
	if(err != nil ){
		beego.Error("采集在线用户数量出错")
	}
	return n,err;
}

//获取时间段内统计数据
type OnlineCountChart struct{
	Time1 string
	Count1 float64
	Num1 int
}

//countType 1 最高在线 2 日平均 3 月平均
func AllUserOnlineCountGetList(countType int,platform int,date1,date2 int64) (*[]OnlineCountChart, int64) {

	var o = orm.NewOrm();
	o.Using("goldlog")
	var maps []OnlineCountChart//[]orm.Params

	dateDis := date2 -date1;
	var num int64 ;
	var  err error ;
	sql := "";
	if countType == 1{
		if dateDis <= 24*3600 {	//每5分钟内的最高在线人数
			fmt.Println("//每5分钟内的最高在线人数")
			sql = "SELECT concat(SUBSTRING(WRITETIME, 1,15), IF(SUBSTRING(WRITETIME, 16,1) >='5','5','0')) as Time1"
			sql = sql + " , max(USERCOUNT) as Count1,count(USERCOUNT) as Num1"
			sql = sql + " FROM AllUserOnlineCount"
			sql = sql + " WHERE UNIX_TIMESTAMP(WRITETIME) BETWEEN " +strconv.FormatInt(date1,10) +" and " +strconv.FormatInt(date2,10) 
			sql = sql + " GROUP BY Time1"
		}else if dateDis <= 24*3600*7 {	//每半小时最高在线人数
			fmt.Println("//每半小时最高在线人数")
			sql = "SELECT concat(SUBSTRING(WRITETIME, 1,14), IF(SUBSTRING(WRITETIME, 15,1) >='3','30','00')) as Time1"
			sql = sql + " , max(USERCOUNT) as Count1,count(USERCOUNT) as Num1"
			sql = sql + " FROM AllUserOnlineCount"
			sql = sql + " WHERE UNIX_TIMESTAMP(WRITETIME) BETWEEN " +strconv.FormatInt(date1,10) +" and " +strconv.FormatInt(date2,10) 
			sql = sql + " GROUP BY Time1"
		}else{ //每天最高在线人数
			fmt.Println("//每天最高在线人数")
			sql = "SELECT DATE_FORMAT(WRITETIME,'%Y-%m-%d') AS Time1,max(USERCOUNT) as Count1,count(USERCOUNT) as Num1"
			sql = sql + " FROM AllUserOnlineCount" 
			sql = sql + " WHERE UNIX_TIMESTAMP(WRITETIME) BETWEEN " +strconv.FormatInt(date1,10) +" and " +strconv.FormatInt(date2,10) 
			sql = sql + " GROUP BY Time1"
		}
	}else if countType == 2{ //日平均在线统计
		fmt.Println("//日平均在线统计")
		sql = "SELECT DATE_FORMAT(WRITETIME,'%Y-%m-%d') AS Time1,avg(USERCOUNT) as Count1,count(USERCOUNT) as Num1"
		sql = sql + " FROM AllUserOnlineCount" 
		sql = sql + " WHERE UNIX_TIMESTAMP(WRITETIME) BETWEEN " +strconv.FormatInt(date1,10) +" and " +strconv.FormatInt(date2,10) 
		sql = sql + " GROUP BY Time1"
	}else if countType == 3{//月平均在线统计
		fmt.Println("//月平均在线统计")
		sql = "SELECT DATE_FORMAT(WRITETIME,'%Y-%m') AS Time1,avg(USERCOUNT) as Count1,count(USERCOUNT) as Num1"
		sql = sql + " FROM AllUserOnlineCount" 
		sql = sql + " WHERE UNIX_TIMESTAMP(WRITETIME) BETWEEN " +strconv.FormatInt(date1,10) +" and " +strconv.FormatInt(date2,10) 
		sql = sql + " GROUP BY Time1"
	}
	
	fmt.Println(dateDis,"====================11:",strconv.FormatInt(date1,10))
	fmt.Println(sql);
	num,err = o.Raw(sql).QueryRows(&maps);

	if err != nil {
		beego.Error("统计在线人数sql错误:",err.Error())
	}


	fmt.Println(maps);
	return &maps,num; 

}

/*==============================================================================================================
//游戏信息表
CREATE TABLE `GameInfo` (
	`id` int(11) NOT NULL AUTO_INCREMENT,
	`KindID` int(11) NOT NULL DEFAULT '0' COMMENT '游戏类型',
	`GameName` varchar(64) DEFAULT '',
	`RoomID1` int(11) NOT NULL DEFAULT '0' COMMENT '房间ID',
	`RoomType1` int(11) NOT NULL DEFAULT '0' COMMENT '房间类型1',
	`RoomName1` varchar(64) NOT NULL DEFAULT '' COMMENT '房间名1',
	`RoomID2` int(11) NOT NULL DEFAULT '0' COMMENT '房间ID',
	`RoomType2` int(11) NOT NULL DEFAULT '0' COMMENT '房间类型1',
	`RoomName2` varchar(64) NOT NULL DEFAULT '' COMMENT '房间名1',
	`RoomID3` int(11) NOT NULL DEFAULT '0' COMMENT '房间ID',
	`RoomType3` int(11) NOT NULL DEFAULT '0' COMMENT '房间类型1',
	`RoomName3` varchar(64) NOT NULL DEFAULT '' COMMENT '房间名1',
	`RoomID4` int(11) NOT NULL DEFAULT '0' COMMENT '房间ID',
	`RoomType4` int(11) NOT NULL DEFAULT '0' COMMENT '房间类型1',
	`RoomName4` varchar(64) NOT NULL DEFAULT '' COMMENT '房间名1',
	`RoomID5` int(11) NOT NULL DEFAULT '0' COMMENT '房间ID',
	`RoomType5` int(11) NOT NULL DEFAULT '0' COMMENT '房间类型1',
	`RoomName5` varchar(64) NOT NULL DEFAULT '' COMMENT '房间名1',
	PRIMARY KEY (`id`)
  ) ENGINE=InnoDB AUTO_INCREMENT=98 DEFAULT CHARSET=utf8;
 ==============================================================================================================*/
 type GameInfo struct {
	ID  int `orm:"pk;auto"` //int(10) unsigned
	KindID int //` int(11) NOT NUL
	GameName string //` varchar(64) D
	RoomID1 int //` int(11) NOT NU
	RoomType1 int //` int(11) NOT 
	RoomName1 string //` varchar(64) 
	RoomID2 int //` int(11) NOT NU
	RoomType2 int //` int(11) NOT 
	RoomName2 string //` varchar(64) 
	RoomID3 int //` int(11) NOT NU
	RoomType3 int //` int(11) NOT 
	RoomName3 string //` varchar(64) 
	RoomID4 int //` int(11) NOT NU
	RoomType4 int //` int(11) NOT 
	RoomName4 string//` varchar(64) 
	RoomID5 int //` int(11) NOT NU
	RoomType5 int //` int(11) NOT 
	RoomName5 string //` varchar(64) 
 }
 
 func (a *GameInfo) TableName() string {
	return TableName("GameInfo")
}

func GameInfoGetList(page, pageSize  int , filters ...interface{}) ([]*GameInfo, int64) {
	offset := (page - 1) * pageSize
	list := make([]*GameInfo, 0)
	var o = orm.NewOrm();
	o.Using("goldlog")
	query := o.QueryTable(TableName("GameInfo"))
	if len(filters) > 0 {
		l := len(filters)
		for k := 0; k < l; k += 2 {
			query = query.Filter(filters[k].(string), filters[k+1])
			
		}
	}

	total, _ := query.Count()
	query.OrderBy("id").Limit(pageSize, offset).All(&list)

	fmt.Println(list);

	return list, total
}

